import /* React, */ { useState } from 'react';

export const MessageFetcher = () => {
    const [message, setMessage] = useState('');

    const fetchMessage = async () => {
        try {
            const response = await fetch('https://api.example.com/message');
            const data = await response.json();
            setMessage(data.message);
        } catch (error) {
            console.error('Fetching message failed:', error);
            setMessage('Error fetching message');
        }
    };

    return (
        <div>
            <button onClick={fetchMessage}>Fetch Message</button>
            {message && <p>{message}</p>}
        </div>
    );
};